package mo.daliy;

public class L3176 {

    public int maximumLength(int[] nums, int k) {
        int[][] dp = new int[nums.length][k+1];
        int ret = 1;
        for (int i = 0; i < nums.length; i++) {
            for (int t = 0; t <= k; t++) {
                int ans = 1;
                for (int j = 0; j < i; j++) {
                    if (nums[j] == nums[i]) {
                        ans = Math.max(dp[j][t]+1, ans);
                    } else if (t > 0) {
                        ans = Math.max(dp[j][t-1]+1, ans);
                    }
                }
                dp[i][t] = ans;
                ret = Math.max(ret, ans);
            }
        }
        return ret;
    }

}
